/**
 * 
 */
package com.gaolinjie.controller;

import java.util.HashMap;
import java.util.List;

import com.gaolinjie.model.Blog;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.JMap;
import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.SqlPara;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.plugin.redis.Cache;
import com.jfinal.plugin.redis.Redis;

/**
 * @author jinyulinlang 2018年7月15日
 */
public class IndexController extends Controller {
	public void index() {
		String[] v = getParaValues("test");

		renderTemplate("index.html");
	}

	public void add() {
		renderTemplate("add.html");
	}

	public void forwardActionTest1() {
		String a1 = getPara("a1", "");
		String a2 = getPara("a2", "");
		String a3 = getPara("a3", "");
		String a4 = getPara("a4", "");
		if (StrKit.isBlank(a1) || StrKit.isBlank(a2)) {
			forwardAction("/forwardActionTest2");
		} else {
			forwardAction("/forwardActionTest3");
		}
	}

	@Before({ Tx.class })
	public void forwardActionTest2() {
		String a3 = getPara("a3", "");
		String a4 = getPara("a4", "");
		setAttr("a3", a3);
		setAttr("a4", a4);
		renderJson();
	}
	@Before({ Tx.class })
	public void forwardActionTest3() {
		String a1 = getPara("a1", "");
		String a2 = getPara("a2", "");
		setAttr("a1", a1);
		setAttr("a2", a2);
		renderJson();
	}

	private void doAdd() {
		Blog model = getModel(Blog.class);
		System.out.println("model----->" + model);
		renderText("提交成功");

	}

	/**
	 * 
	 */
	public void sqlManager() {
		String sql = Blog.dao.getSql("blogId_btween9And12");
		System.out.println("sql------->" + sql);
		renderJson(Blog.dao.find(sql, 9, 12));
	}

	/**
	 * 
	 */
	public void sqlManager1() {
		String sql = Blog.dao.getSql("blogId_9And12");
		System.out.println("sql------->" + sql);
		renderJson(Blog.dao.find(sql, 9, 12));
	}

	/**
	 * 
	 */
	public void sqlManager2() {
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
		Kv cond = Kv.create().set("min_9", 9).set("max_12", 12);
		SqlPara sql = Blog.dao.getSqlPara("blogId_9And12_new", cond);
		System.out.println("sql------->" + sql);
		renderJson(Blog.dao.find(sql));
	}

	/**
	 * 
	 */
	public void sqlManager3() {
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("min_9", 9);
		map.put("max_12", 12);
		SqlPara sql = Blog.dao.getSqlPara("blogId_9And12_new", map);
		System.out.println("sql------->" + sql);
		renderJson(Blog.dao.find(sql));
	}

	/**
	 * 
	 */
	public void testTempalte() {
		render("template-test.html");
	}

	public void addRedis() {
		String set = Redis.use().set("age111", "我是高手高手高高手");
		renderText("set--------->" + set);
	}

	public void getRedis() {
		Object object = Redis.use().get("age111");
		System.out.println("object---------" + object);

	}

}
